﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using BLL.Business;
using BLL.Controler;

namespace TTCN_QLDiemC3.MyUserControl.UCHienThi
{
    public partial class UCThongKeDiemTKCaNam : UserControl
    {
        String idKhoi = null;
        String idNam = null;
        String idLop = null;
        public UCThongKeDiemTKCaNam()
        {
            InitializeComponent();
            showCBBNamHoc();
            showCBBKhoi();
        }
        /// <summary>
        /// Hiển thị cbbNamHoc
        /// </summary>
        void showCBBNamHoc()
        {
            BangDiemBUO bdBUO = new BangDiemBUO();
            cbbNamHoc.DataSource = bdBUO.getAllNamHoc();
            cbbNamHoc.DisplayMember = "TenNamHoc";
            cbbNamHoc.ValueMember = "id_NamHoc";
        }
        /// <summary>
        /// Hiển thị cbbKhoi
        /// </summary>
        void showCBBKhoi()
        {
            BangDiemBUO bdBUO = new BangDiemBUO();
            cbbKhoi.DataSource = bdBUO.getAllKhoi();
            cbbKhoi.DisplayMember = "TenKhoi";
            cbbKhoi.ValueMember = "id_Khoi";
        }

        private void cbbKhoi_SelectedIndexChanged(object sender, EventArgs e)
        {
            idKhoi = cbbKhoi.SelectedValue.ToString();
            idNam = cbbNamHoc.SelectedValue.ToString();
            BangDiemBUO bdBUO = new BangDiemBUO();
            cbbLop.DataSource = bdBUO.showDSLopTungNam(idKhoi, idNam);
            cbbLop.DisplayMember = "TenLop";
            cbbLop.ValueMember = "id_Lop";
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            
            idLop = cbbLop.SelectedValue.ToString();
            IList<KQDiemTongHopTheoNamInfo> ketqua = KQTongHopTheoNamCtrl.LayDsKQHocKyTongHop(idLop, idNam);
            dataGridView1.DataSource = ketqua;
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            ThongKeDiemTKCaNamReport r = new ThongKeDiemTKCaNamReport();
            r.DataSource = dataGridView1.DataSource;
            r.Load(cbbNamHoc.Text, cbbKhoi.Text, cbbLop.Text);
            r.ShowPreviewDialog();
        }
    }
}
